$(function() {
	
	//主面板初始化
	$('#workflowDeploymentPanel').panel({
		border:false
	});
	
	//初始化BTN
	initBtnUI();
	
	//初始化数据表
	initDataGridUI();
	
});

//初始化BTN
function initBtnUI(){
	$('#addWorkflowDeployBtn').linkbutton({plain:true,iconCls:'icon-add'});
	$('#workflowDeployBtn').linkbutton({plain:true,iconCls:'icon-process'});
	$('#closeWorkflowDeploymentBtn').linkbutton({plain:true,iconCls:'icon-close'});
}

//初始化数据表
function initDataGridUI(){
	//初始化数据表格
	$('#workflowDeploymentDataGrid').datagrid({
		url:'workflowDeploymentAjax!loadWorkflowDeploymentData',
		nowrap: false,
		border:false,
		striped: true,
		collapsible:true,
		sortName: 'id',
		singleSelect:true,
		sortOrder: 'desc',
		remoteSort: false,
		pagination:true,
		rownumbers:true,
		idField:'id',
		columns:[[
			{field:'fileName',title:'文件名称',width:200},
			{field:'processName',title:'流程名称',width:200},
			{field:'processKey',title:'流程键值',width:200},
			{field:'version',title:'部署版本',width:80},
			{field:'descript',title:'流程描述',width:350}
		]]
	});

	//分页
	var pager = $('#workflowDeploymentDataGrid').datagrid('getPager');
	$(pager).pagination({
		pageSize: 15,
		pageList: [15, 30, 50, 100],
		beforePageText: '第',
		afterPageText: '页    共 {pages} 页',
		displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
		onSelectPage:function(pageNumber, pageSize){
			$('#workflowDeploymentDataGrid').datagrid('options').url = 'workflowDeploymentAjax!loadWorkflowDeploymentData?pageNo=' + pageNumber + '&pageSize='+ pageSize;
			$('#workflowDeploymentDataGrid').datagrid('reload', pageNumber);
		}
	});
}

//部署流程
function workflowDeployment(){
	var row = $('#workflowDeploymentDataGrid').datagrid('getSelected');
	if(ROW_IS_NOT_NULL(row)){
		$.post('workflowDeploymentAjax!deployment', {fileName:row.fileName, id:row.id},
				function(data){
					$.messager.alert('提示',data.message);
					$('#workflowDeploymentDataGrid').datagrid('reload');
			}, 'json');
	}
	
}

